package com.china08.yxyapi.api.manage.sch.platform.resource;

import java.lang.reflect.InvocationTargetException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.resource.SearchResourceModel;
import com.china08.yxyapi.security.profile.YxyProfile;
import com.china08.yxyapi.service.yxyresource.YxyResourceSchService;

import io.swagger.annotations.ApiOperation;

/**
 * 学校未审核资源数量
 * 
 * @author renruihu
 *
 */
@CrossOrigin
@RestController("SchResourceNotAuditNumController")
public class ResourceNotAuditNumController extends YxyApiBaseController {

    // @Autowired
    // private YxyResourceService yrs;

    @Autowired
    private YxyResourceSchService yxyResourceSchSchService;

    @ApiOperation(value = "学校未审核资源数量")
    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/sch/platform/resource/notaudit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel find(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel)
            throws IllegalAccessException, InvocationTargetException {
        RespModel model = new RespModel();
        YxyProfile profile = getProfile(request, response);
        String schoolId = profile.getSchoolId();
        SearchResourceModel searchResourceModel = new SearchResourceModel();
        searchResourceModel.schoolId = schoolId;
        searchResourceModel.phaseId = reqModel.phase;
        searchResourceModel.subjectId = reqModel.subject;
        searchResourceModel.keyword = reqModel.keyword;
        searchResourceModel.status = 0; // 未审核
        searchResourceModel.viewScope = 1;
        searchResourceModel.isYxYunRes = 0;
        long num = yxyResourceSchSchService.notReviewedNum(searchResourceModel);
        model.notAuditNum = num;
        return model;
    }

    protected static class ReqModel {
        public String phase;
        public String subject;
        public String keyword;
    }

    protected static class RespModel {
        // 资源未审核数量
        public long notAuditNum;
    }
}
